<?php

namespace web\api\controller;

/**
 * Description of News
 * 公告
 */
class Notice extends ApiBase {

    public function noticeList(){
        try {
//            $lang = $this->_post('lang')=='en-us'?1:0;
//            $keyword = $this->_post('keyword');//标题
//            $type = $this->_post('type');//类型
            // if(!in_array($type, [1,2,3,4])){
            //     return $this->failJSON('类型错误');
            // }
            $filter = ' type = 1 and status = 1 ';
//            if ($keyword != null) {
//                $filter .= ' and title like \'%' . $keyword . '%\'';
//            }
            // $filter .= ' and lang = '.$lang;
            $m = new \addons\config\model\Notice();
            $list = $m->getNoticeList($this->getPageIndex(),$this->getPageSize(),$filter);
            foreach ($list as &$value){
                $value['content'] = htmlspecialchars_decode($value['content']);
            }
            return $this->successJSON($list);
            
        } catch (\Exception $ex) {
            return $this->failJSON($ex->getMessage());
        }
    }
    
    public function noticeDetail(){
        try {
            $id = $this->getParamVal('id');//标题
            $m = new \addons\config\model\Notice();
            $list = $m->find($id);
            $list['content'] = htmlspecialchars_decode($list['content']);
            return $this->successJSON($list);
        } catch (\Exception $ex) {
            return $this->failJSON($ex->getMessage());
        }
    }
    /*
     * 图片D06 常见问题
     */
    public function problem(){
        $m = new \addons\config\model\Help();
         try {
            $lang = $this->_post('lang')?$this->_post('lang'):'zh-cn';//类别
            if($lang=='zh-cn'){
                $filter = 'type = 1';
            }elseif($lang=='en-us'){
                $filter = 'type = 3';
            }else{
                $filter = 'type = 1';
            }
            // $filter = "type = 3";
            $list = $m->getList($this->getPageIndex(),$this->getPageSize(),$filter);
            return $this->successJSON($list);
        } catch (\Exception $ex) {
            return $this->failJSON($ex->getMessage());
        }
    }
}
